package com.jjkj.base.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.kit.StrKit;
import com.jjkj.base.common.ResultCode;
import com.jjkj.base.exception.BusinessException;
import io.jboot.web.controller.JbootController;

public class JwtInterceptor implements Interceptor {
    @Override
    public void intercept(Invocation inv) {
        if (inv.getController() instanceof JbootController) {
            JbootController c = (JbootController) inv.getController();
            String userId = c.getJwtPara("userId");

            if (StrKit.isBlank(userId)) {
                throw new BusinessException(ResultCode.NO_AUTH, "未登录");
            }
        }

        inv.invoke();
    }
}
